<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>深圳市管理系统</title>
</head>
<body>
<form id="form_login" action="${pageContext.request.contextPath}/login.xhtml" method="post">
	<input type="text"  name="user.account" class="i-a" id="user" onchange="cleanpwd();"/>
	<input type="password" name="user.password" class="i-a" id="psw" />
	 <a id="btn" class="btn" onclick="loginFun.login(); return false;"></a>
</form>
<script type="text/javascript">
function cleanpwd(){
	$('#psw').val('');
}
function getParent(root, depth) {
	if (root.parent && root.parent != root && depth <= 10) {
		depth = depth + 1;
		return getParent(root.parent, depth)
	} else {
		return root;
	}
}

$(document).ready(function() {
	var parent = getParent(window, 0);
	if (parent != window) {
		parent.window.location.reload();
	}

	$('#user').blur(function() {
		loginFun.getPwdAndChk();
	}).focus(function() {
		cleanpwd();
		loginFun.tipsHide();
	}).keydown(function(e) {
		cleanpwd();
		if (e.keyCode == 13) {
			loginFun.getPwdAndChk();
			loginFun.login();
			return false;
		}
	});

	$('#psw').focus(function() {
		loginFun.tipsHide();
	});

	$('#form_login').keydown(function(e) {
		if (e.keyCode == 13) {
			loginFun.login();
		}
	});
});

window.onload = function() {
	loginFun.getLastUser();
};
var loginFun = {
		getLastUser : function() {
			var id = "BCE54B84-5407-41FD-9D16-C8A09E5DA2A0", //GUID
			usr = loginFun.getCookie(id);
			usr = usr ? usr : '';
			$('#user').val(usr);
			loginFun.getPwdAndChk();
		},

		setPwdAndChk : function() {
			var usr = $('#user').val();
			loginFun.setLastUser(usr);
			if ($('#chkrember').is(':checked')) {
				var pwd = $('#psw').val();
				var expdate = new Date();
				expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000));
				loginFun.setCookie(usr, pwd, expdate);
			} else {
				loginFun.resetCookie();
			}
		},

		setLastUser : function(usr) {
			var id = "BCE54B84-5407-41FD-9D16-C8A09E5DA2A0", expdate = new Date();
			expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000));
			loginFun.setCookie(id, usr, expdate);
		},

		getPwdAndChk : function() {
			var usr = $('#user').val(), pwd = loginFun.getCookie(usr);
			if (pwd != null) {
				$('#chkrember').attr('checked', true);
				$('#psw').val(pwd);
			} else {
				$('#chkrember').attr('checked', false);
				$('#psw').val("");
			}
		},

		getCookie : function(name) {
			var arg = name + "=", alen = arg.length, clen = document.cookie.length, i = 0;
			while (i < clen) {
				var j = i + alen;
				if (document.cookie.substring(i, j) == arg)
					return loginFun.getCookieVal(j);
				i = document.cookie.indexOf(" ", i) + 1;
				if (i == 0)
					break;
			}
			return null;
		},

		getCookieVal : function(offset) {
			var endstr = document.cookie.indexOf(";", offset);
			if (endstr == -1)
				endstr = document.cookie.length;
			return unescape(document.cookie.substring(offset, endstr));
		},

		setCookie : function(name, value, expires) {
			var argv = arguments, argc = argv.length, expires = (argc > 2) ? argv[2] : null, path = (argc > 3) ? argv[3] : null, domain = (argc > 4) ? argv[4] : null, secure = (argc > 5) ? argv[5] : false;
			document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
		},

		resetCookie : function() {
			var usr = $('#user').val(), expdate = new Date();
			loginFun.setCookie(usr, null, expdate);
		},

		tipsHide : function() {
			$('#retips').hide();
			$('#etips').parent().hide();
		},

		login : function() {
			loginFun.tipsHide();
			if ($.trim($('#user').val()) == '') {
				$('#etips').html('登录账号不能为空。').parent().show();
				return;
			}
			if ($.trim($('#psw').val()) == '') {
				$('#etips').html('密码不能为空。').parent().show();
				return;
			}
			loginFun.setPwdAndChk();
			form_login.submit();
		}
	};
</script>
</body>
</html>